# Contributor: Sertonix <sertonix@posteo.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rpi-imager
pkgver=1.9.0
pkgrel=0
pkgdesc="A user-friendly tool for creating bootable media for Raspberry Pi devices"
url="https://www.raspberrypi.com/software/"
# only supports little endian
arch="all !s390x"
license="Apache-2.0"
makedepends="
	cmake
	curl-dev
	gnutls-dev
	libarchive-dev
	ninja
	qt6-qtbase-dev
	qt6-qtdeclarative-dev
	qt6-qtsvg-dev
	qt6-qttools-dev
	xz-dev
	"
subpackages="$pkgname-doc"
source="https://github.com/raspberrypi/rpi-imager/archive/v$pkgver/rpi-imager-$pkgver.tar.gz
	devendor.patch
	"
options="!check"

prepare() {
	default_prepare

	# Remove vendored dependencies
	local i
	for i in src/dependencies/*; do
		case $i in
			*/drivelist|*/mountutils|*/sha256crypt) continue ;;
		esac
		rm -r "$i"
	done
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -S src -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_BUILD_TYPE=None \
		-DENABLE_CHECK_VERSION=OFF \
		-DENABLE_TELEMETRY=OFF \
		$crossopts
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	install -Dm644 -t "$pkgdir"/usr/share/applications debian/*.desktop
	install -Dm644 -t "$pkgdir"/usr/share/metainfo debian/*.metainfo.xml
	install -Dm644 -t "$pkgdir"/usr/share/icons/hicolor/128x128/apps debian/rpi-imager.png
	install -Dm644 -t "$pkgdir"/usr/share/man/man1 doc/man/*.1
}

sha512sums="
cbe1b623244b41a513b01e686092c0ea2e5fc6f4544e779742e9dc88fb3c2f6f5839e814a18ef647a8fd347b6f97fd0053e44eb556213dc0052c12565b8a224b  rpi-imager-1.9.0.tar.gz
21b503a3c284b813a063691a768ca648175ea368029cbdd62b2e999da61cb94b1f8cdb5dfddec7911f75f725f9bc41dd7fb06374437411758a5798b53a3283a5  devendor.patch
"
